package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端订单接口")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 客户端取消订单
     * @param dto
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("客户端取消订单")
    public Result cancelOrder(@RequestBody OrdersCancelDTO dto){
        ordersService.cancelAdminOrder(dto);
        return Result.success();
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result statistics(){
        OrderStatisticsVO statistics = ordersService.statistics();
        return Result.success(statistics);
    }

    /**
     * 订单搜索
     * @param dto
     * @return
     */
    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result conditionSearch(OrdersPageQueryDTO dto){
        PageResult pageResult = ordersService.conditionSearch(dto);
        return Result.success(pageResult);
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result adminDetailsOrder(@PathVariable Long id){
        OrderVO orderVO = ordersService.oderDetailById(id);
        return Result.success(orderVO);
    }

    /**
     * 接单
     * @param dto
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO dto){
        ordersService.confirmOrder(dto);
        return Result.success();
    }

    /**
     * 拒单
     * @param dto
     * @return
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO dto){
        ordersService.rejectionOrder(dto);
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result deliveryOrder(@PathVariable Long id){
        ordersService.deliveryOrder(id);
        return Result.success();
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result completeOrder(@PathVariable Long id){
        ordersService.completeOrder(id);
        return Result.success();
    }


}
